<?php

/*
  VoIP Wholesale 1.0
  ------------------
  Document   : module_families_add
  Created on : Sep 14, 2011, 4:32:27 PM
  Author     : Milos Jovanovic <miloscode@gmail.com>
  Description:

 */
?>
<div id="page-title"><?=lang('term_families')?></div>

<div id="page-desc"><?=lang('text_families_desc')?></div>

<div class="ui-widget"> 
    <div id="content">
        <div class="module-options">
            <button id="module-add-origin-trunk"><?=lang('button_add_new_family')?></button>
        </div>
        
        <fieldset>
        <!-- PAGE CONTENT -->
	<form action="" method="post" id="new-trunk" onsubmit="return false;"> 
		<fieldset class="ui-widget-content ui-corner-all">
		<legend class="ui-widget-content ui-corner-all"><?=lang('text_family_information')?></legend>
				<p>
					<label><?=lang('term_short_name')?></label> 
					<input type="text" name="data[short_name]" id="family_short_name" class="deactivated ui-state-disabled text ui-widget-content ui-corner-all" value="<?=$family['short_name']?>" /> 
					<div id="family_short_name_status"></div>
                </p>
				<p>
					<label><?=lang('term_description')?></label> 
					<textarea name="data[description]" class="ui-widget-content module-textarea"><?=$family['description']?></textarea>
				</p>
			</fieldset>
		<fieldset class="ui-widget-content ui-corner-all">
		<legend class="ui-widget-content ui-corner-all"><?=lang('text_trunks')?></legend>			
			<br />
			<script>
				var linked_trunks = <?=count($linked_trunks)?>;
			</script>			
			<div id="trunks">
				<?php
				if(count($linked_trunks) > 0)
				{
					$text = "";
					foreach($linked_trunks as $trunk_id => $short_name)
					{
						$tru = $this->PACKAGE->routing->trunks->get_trunk_as_array_by_id($trunk_id,'termination');
						$car = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($tru['carrier_id']);
					
						$text .= "<div class='row'><input type='hidden' name='data[trunks][]' value='".$trunk_id."' /><span class='virtual-links' rel='".$trunk_id."'>".$car['username']." - ".$short_name."</span>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='show_unlink_trunk_dialog(this, \"".$trunk_id."\", \"".$family['id']."\")'>".lang('term_delete')."</a>";
						$text .= "<a class='open-event' href='javascript:void(0);' title='".$this->MODULE->module_trunks->show_status_desc($trunk_id,"termination")."'>".$this->MODULE->module_trunks->show_status_msg($trunk_id,"termination")."</a>"."&nbsp;&nbsp;&nbsp;";
						$text .= "</div>";
						print $text;
						$text = "";
					}
					print "<hr />";
				}
				else
				{
					print lang('term_no_trunks_linked');
				}
				?>
			</div>
		
			<br />
			<a href="javascript:void(0);" id="link-trunks-button" class="button ui-state-default ui-corner-all" title="<?=lang('term_add_trunk')?>"><span class="ui-icon ui-icon-circle-plus"></span><text><?=lang('term_link_trunks')?></text></a>
		
		</fieldset>		
				<p>
					<input type="hidden" name="data[confirm]" id="confirm" value="false"/>
					<input type="hidden" name="data[family_id]" id="confirm" value="<?=$family['id']?>"/>
					<div id="response"></div><br />
					<button id="module-save-edit-family"><?=lang('button_save')?></button>
				</p>
	 </form> 

	 </div>    
</div>   

						<div id="link-trunk">
							<p>			
								<form action="javascript: void(0);" id="modal-form" method="post">
								<?php foreach($trunks as $trunk){
								$car = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($trunk['carrier_id']);
								?>
								 <div class="field-parent <?php if(isset($linked_trunks[$trunk['id']])){?>hidden-trunk<?php }?>" id="field_<?=$trunk['id']?>">
									<div class="label"><input type="checkbox" class="checkboxes" name="trunks[<?=$trunk['id']?>]" value="<?=$trunk['short_name']?>"/></div>
									<div class="text"><span class='virtual-links' rel='<?=$trunk['id']?>'><?=$car['username']?> - <?=$trunk['short_name']?></span>&nbsp;&nbsp;&nbsp;<a class="open-event" href="javascript:void(0);" title="<?=$this->MODULE->module_trunks->show_status_desc($trunk['id'],"termination")?>"><?=$this->MODULE->module_trunks->show_status_msg($trunk['id'],"termination")?></a></div><br />
								 </div>
								<?php }?>
								</form>
							</p>
						</div>	
						
						<div id="unlink-trunk" title="<?=lang('term_confirm_action')?>">
							<p>	
								<?=lang('text_this_trunk_has_previously_been_linked_with_this_family')?><br />
								<?=lang('text_if_you_confirm_the_trunk_will_be_unlinked_in_database')?><br /><br />
								<?=lang('text_if_you_click_yes_deletion_doesnt_start_instantly')?>								
							</p>
						</div>
